import requests

# 原始的http get请求 报文结构
'''
get https://www.baidu.com/s?wd=python HTTP/1.1\r\n
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36\r\n
Cookie: BD_UPN=123253; BIDUPSID=9E4C6E8F9C8C7D9D7D9D9D9D9D9D9D9D; PSTM=1638359399; BAIDUID=9E4C6E8F9C8C7D9D7D9D9D9\r\n
Referer: http://www.baidu.com/\r\n
\r\n
'''

# 模拟发送get请求
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36',
    # 'Cookie': 'BD_UPN=123253; BIDUPSID=9E4C6E8F9C8C7D9D7D9D9D9D9D9D9D9D; PSTM=1638359399; BAIDUID=9E4C6E8',
    # 'Referer': 'http://www.baidu.com/'
}
params = {
    'wd':'python'
}
response = requests.get('https://img2.baidu.com/it/u=266927891,953958166&fm=253&fmt=auto&app=138&f=JPEG?w=568&h=305',headers=headers)
result = response.content
with open('baidu.jpg','wb') as f:
    f.write(result)

# with open('baidu.html','w',encoding='utf-8') as f:
#     f.write(html_str)
# response.status_code #http状态
# response.text  #返回字符串类型 自动编码
# response.content  #返回字节类型
# response.content.decode('utf-8')  # 解码 只针对文本数据